package com.relytosoft.mizar.media.analyze.services.controller.face;

import com.relytosoft.dubhe.common.core.object.ResponseResult;
import com.relytosoft.mizar.media.analyze.services.controller.AyDataBaseController;
import com.relytosoft.mizar.media.analyze.services.service.face.AyFaceDataService;
import com.relytosoft.mizar.media.common.entity.pojo.request.btdl.common.BtdlDataReq;
import com.relytosoft.mizar.media.common.entity.pojo.request.btdl.common.BtdlFaceControlReq;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Objects;

/**
 * @author wss
 * @version 1.0
 * @date 2022/5/31 11:04
 */
@RestController
@RequestMapping("/analyze/face/data")
@Api(tags = "人脸接收算法推送数据接口")
public class AyFaceDataController extends AyDataBaseController {

    @Autowired
    private AyFaceDataService ayFaceDataService;

    @ApiOperation(value = "原始数据接收")
    @PostMapping(value = "/raw")
    public ResponseResult<Void> receiveRawData(HttpServletRequest request) {
        BtdlDataReq btdlDataReq = toDataReq(request);
        if (Objects.isNull(btdlDataReq) || Objects.isNull(btdlDataReq.getVideoSliceListObject())) {
            return ResponseResult.fail();
        }
        ayFaceDataService.receiveRawData(btdlDataReq);
        return ResponseResult.ok();
    }


    @ApiOperation(value = "布控告警接收")
    @PostMapping(value = "/control")
    public ResponseResult<Void> receiveControlData(HttpServletRequest request) {
        List<BtdlFaceControlReq> btdlFaceControlReqs = toFaceControlReq(request);
        if (btdlFaceControlReqs.isEmpty()) {
            return ResponseResult.fail();
        }
        ayFaceDataService.receiveControlData(btdlFaceControlReqs);
        return ResponseResult.ok();
    }

}
